<template>
  <div>
    <el-row>
      <el-col>
        <el-form :inline="true" :model="formInline">
          <el-form-item>
            <el-input size="mini" v-model="formInline.num" placeholder="请输入设备编号"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input size="mini" v-model="formInline.name" placeholder="请输入设备名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="mini" @click="search">查询</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row class="buttonList">
      <el-col>
        <el-button type="primary" :disabled="btnDisabled" size="mini" @click="newAdd">维修</el-button>
      </el-col>
    </el-row>
    <el-row>
      <!--<el-col :span="4">
        <el-tree accordion highlight-current :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
      </el-col>-->
      <el-col :span="24">
        <el-table
                :data="tableData"
                size="mini"
                @selection-change="handleSelectionChange"
                border
                style="width: 100%">
          <el-table-column
                  align="center"
                  type="selection"
                  width="55">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="NUM"
                  label="设备编号">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="NAME"
                  width="100px"
                  label="资产名称">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="CLASSIFICATIONNAME"
                  label="归类属性">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="AMOUNT"
                  label="单价/元">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="SPECS"
                  label="规格">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="MODEL"
                  width="180px"
                  label="型号">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="TYPENUM"
                  label="分类号">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="COMPANYNAME"
                  label="单位名称">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="COMPANY"
                  label="使用单位">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="DIRECTIONNAME"
                  label="使用方向">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="TYPENUM"
                  label="分类号">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="STATUS"
                  label="状态">
            <template slot-scope="scope">
              {{scope.row.STATUS ? '启用': '禁用'}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="ISVALUABLE"
                  label="是否贵重">
            <template slot-scope="scope">
              {{scope.row.ISVALUABLE ? '是': '否'}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="ISCONSUMABLES"
                  label="是否易耗">
            <template slot-scope="scope">
              {{scope.row.ISCONSUMABLES ? '是': '否'}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="ISNORMAL"
                  label="是否正常">
            <template slot-scope="scope">
              {{scope.row.ISNORMAL ? '是': '否'}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="ISAPPOINTMENT"
                  label="预约">
            <template slot-scope="scope">
              {{scope.row.ISAPPOINTMENT ? '是': '否'}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="ISRECEIVE"
                  label="领用">
            <template slot-scope="scope">
              {{scope.row.ISRECEIVE ? '是': '否'}}
            </template>
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="PRESENTNAME"
                  label="现状">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="COUNTRY"
                  label="国别">
          </el-table-column>
          <el-table-column
                  align="center"
                  prop="SOURCENAME"
                  label="来源">
          </el-table-column>
        </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                background
                layout="total, sizes, prev, pager, next, jumper"
                :page-size="pagination.pageSize"
                :total="pagination.total"
                :page-sizes="[10, 20, 30, 50, 100]"
        >
        </el-pagination>
      </el-col>
    </el-row>
    <el-dialog title="设备维修" :visible.sync="dialogFormVisible" center width="60%">
      <el-form :model="form" :label-width="formLabelWidth">
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备名称">
              <el-input size="mini" v-model="form.name" autocomplete="off" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维修人">
              <el-input size="mini" v-model="form.repairName" autocomplete="off" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="维修内容">
              <el-input type="textarea" size="mini" v-model="form.repairCause" autocomplete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogFormVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "maintenance",
    data() {
      return{
        fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}],
        dialogImageUrl: '',
        dialogVisible: false,
        form: {},
        data: [],
        defaultProps: {
          children: 'list',
          label: 'NAME'
        },
        pagination: {
          pageSize: 20,
          total: 1,
          pageNo: 1
        },
        dialogFormVisible: false,
        formLabelWidth: '120px',
        formInline: {},
        tableData: [],
        btnDisabled: true,
        tableVal: []
      }
    },
    created() {
      this.getData(this.pagination.pageSize, this.pagination.pageNo);
      this.getTreeData()
    },
    methods: {
      getTreeData() {
        this.$post('/public/findStructureByTestBase').then(res => {
          this.data = res.data.data;
        })
      },
      search() {
        this.$post('/insrtument/findInstrument', {
          pageSize:this.pagination.pageSize,
          pageNo: 1,
          name: this.formInline.name,
          num: this.formInline.num,
          isNormal: 0
        }).then(res => {
          if(res.data.status != 1) {
            this.$message.error('条件输入错误，请检查');
            return;
          }
          this.pagination.total = res.data.data.total;
          this.tableData = res.data.data.dataList;
        })
      },
      getData(pageSize, pageNo) {
        this.$post('/insrtument/findInstrument', {pageSize, pageNo, isNormal: 0}).then(res => {
          this.tableData = res.data.data.dataList;
          this.pagination.total = res.data.data.total;
        })
      },
      newAdd() {
        this.form.name = this.tableVal[0].NAME;
        this.form.repairName = this.$store.getters.getUserMessage.name;
        this.form.instrumentId = this.tableVal[0].ID;
        this.dialogFormVisible = true;
      },
      submit() {
        this.$post('/insrtumentRepair/add', this.form).then(res => {
          if(res.data.status === 1) {
            this.$message.success('请求成功');
            this.getData(20, 1);
            this.dialogFormVisible = false;
          } else {
            this.$message.error(res.data.msg)
          }
        })
      },
      handleSizeChange(size) {
        this.pagination.pageSize = size;
        this.getData(size, this.pagination.pageNo);
      },
      handleCurrentChange(page) {
        this.pagination.pageNo = page;
        this.getData(this.pagination.pageSize, page);
      },
      handleSelectionChange(val) {
        if (val.length === 1) {
          this.btnDisabled = false;
        }else{
          this.btnDisabled = true;
        }
        this.tableVal = val;
      },
      handleNodeClick(data, node) {
        console.log(data);
        let departmentId = '';
        let testBaseId = '';
        let testId = '';
        if(node.level === 1) {
          departmentId = data.ID;
        }
        if(node.level === 2) {
          testBaseId = data.ID;
        }
        if(node.level === 3) {
          testId = data.ID;
        }
        this.$post('/insrtument/findInstrument',{
          departmentId, testBaseId,testId,
          pageSize: this.pagination.pageSize,
          pageNo: 1
        }).then(res => {
          this.tableData = res.data.data.dataList;
          this.pagination.total = res.data.data.total;
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .search{
    margin-bottom: 10px;
  }
  /deep/.el-select{
    width: 100%;
  }
  .addDev {
    /deep/.el-form-item__content {
      display: flex;
    }
  }
  /deep/.el-divider{
    background: #409eff;
  }
  /deep/.el-divider__text{
    font-size: 18px;
    color: #409eff;
  }
  /deep/.el-date-editor.el-input, .el-date-editor.el-input__inner {
    width: 100%
  }
</style>
